<?php require_once('../includes/conn.php'); ?>
<?php
session_start();
include("../includes/settings.inc.php");

//print_r($_POST);
	$query_rs_pages = "SELECT * FROM news WHERE 1 and ntype = '".$_REQUEST['for']."' ORDER BY orderid ASC";
	$rs_pages = mysql_query($query_rs_pages) or die(mysql_error());
	while($row_rs_pages = mysql_fetch_array($rs_pages))
	{
		$s35 = "update news set orderid = '".$_REQUEST["orderid".$row_rs_pages["nid"].""]."' where nid = '".$row_rs_pages["nid"]."'";
		$q35 = mysql_query($s35) or die($s35); 
	}

if(isset($_POST['delete']) && count($_POST['delete'])>0)
{
  foreach($_POST['delete'] as $delete_data)
  { 
  	$s = "delete FROM news where nid = '".$delete_data."' and ntype = '".$_REQUEST['for']."'";
  	$q = mysql_query($s) or die($s);
	
  }  
}

if(isset($_POST['status']) && count($_POST['status'])>0)
{
  foreach($_POST['status'] as $status_data)
  { 
 	
	$s1 = "SELECT nstatus FROM news where nid = '".$status_data."' and ntype = '".$_REQUEST['for']."'";
  	$q1 = mysql_query($s1) or die($s1);
	$r1 = mysql_fetch_array($q1);
	
	 if($r1["nstatus"] == "1")
	 {
	 	$status = 0;
	 }
	 else
	 {
	 	$status = 1;
	 }
  	 $s = "update news set nstatus  = '".$status."' where nid  = '".$status_data."' and ntype = '".$_REQUEST['for']."'";
  	 $q = mysql_query($s) or die($s);
  } 
} 
if(isset($_POST['main']) && count($_POST['main'])>0)
{
  foreach($_POST['main'] as $main_data)
  { 
 	
	$s1 = "SELECT main FROM news where nid = '".$main_data."' and ntype = '".$_REQUEST['for']."'";
  	$q1 = mysql_query($s1) or die($s1);
	$r1 = mysql_fetch_array($q1);
	
	 if($r1["main"] == "1")
	 {
	 	$status = 0;
	 }
	 else
	 {
	 	$status = 1;
	 }
  	 $s = "update news set main  = '".$status."' where nid  = '".$main_data."' and ntype = '".$_REQUEST['for']."'";
  	 $q = mysql_query($s) or die($s);
  } 
} 
  echo "<script language='javascript'>
   		alert('Successfully Updated the Records');
   		window.location ='".$_SERVER['HTTP_REFERER']."';
   		 </script>";  
?>